//
//  UIImageView+WebImage.swift
//  simpleWeibo
//
//  Created by sunmumu on 2018/10/15.
//  Copyright © 2018年 孙林. All rights reserved.
//

import SDWebImage

extension UIImageView {
    
    /// 隔离 SDWebImage 设置图像函数
    ///
    /// - Parameters:
    ///   - urlString: urlString
    ///   - placeholder: placeholder
    func cz_setImage(urlString: String?, placeholder: UIImage?, isAvatar: Bool) {
        guard let urlString = urlString,
            let url = URL(string: urlString)
            else {
                image = placeholder
                return
        }
        sd_setImage(with: url, placeholderImage: placeholder, options: []) {[weak self] (_, _, _, _) in
            if isAvatar {
                self?.image = self?.image?.cz_avatarImage(size: self?.bounds.size)
            }
        }
        
    }
}
